<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>学生管理管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
	    var now = new Date();
	    var year = now.getFullYear(); //得到年份
	    var month = now.getMonth(); //获取当前月份(0-11,0代表1月)
	    var day = now.getDate(); //获取当前日(1-31)
		$(document).ready(function() {
			$("#stuName").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					/* loading('正在提交，请稍等...');
					form.submit(); */
					postOrderDetil(form);
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#enrtYear").blur(function(){
				var str;
				var stuGrade;
				var enrtYear = $("#enrtYear").val();
				var schoolCode = $("#schoolCodeId").val();
				if(enrtYear == ""){
					$("#stuGrade").val("");
					return;
				}
				if(schoolCode == ""){
					layer.open({
                      icon: 3, title:'提示',
					  content: '请选择所在学校才能判断是几年级！！',
					  scrollbar: false
					});
					return;
				}
				if(month > 8 && day > 1){
				    stuGrade = year - enrtYear;
				}else{
					stuGrade = year - enrtYear - 1;
				}
				checkGrade(schoolCode,stuGrade);
			});
			$("#stuCode").blur(function(){
				var stuCode = $(this).val();
				var url = "${ctx}/student/student/getStuCode";
				$.ajax({
					url :url,
					async: false,
					data :{"stuCode":stuCode},
					success : function(data){
						debugger;
						if(data != ""){
							layer.alert('学号重复，请核对后重新输入！', {
						      skin: 'layui-layer-molv' //样式类名  自定义样式
						      ,closeBtn: 1    // 是否显示关闭按钮
						      ,anim: 2 //动画类型
						      ,btn: ['确认'] //按钮
						      ,icon: 6    // icon
						      ,offset: '0px'
						      ,yes:function(){
						    	  layer.closeAll();
						      }
						     ,btn2:function(){
						    }});
						}else{
							return;
					    }
					}
				});
			});
		});
		
		function postOrderDetil(form) {//表单保存时  将此方法中的数据尽行保存
			
			layer.confirm('确定保存？', {
				icon: 3, title:'提示',
				btn : [ '保存', '取消' ]
			//按钮
			}, function() {
				layer.load(2);
				loading('正在提交，请稍等...');
				form.submit();
			});
		}
		
		function getStuGrade(schoolCode){
			var enrtYear = $("#enrtYear").val();
			var stuGrade;
			$("#stuGrade").val()
			if(enrtYear == "" || schoolCode == ""){
				$("#stuGrade").val("");
				return;
			}
			var stuGrade = year - enrtYear;
			checkGrade(schoolCode,stuGrade);
		}
		function checkGrade(schoolCode,stuGrade){
			var str;
			var url = "${ctx}/sysschool/sysSchool/getSchCode?code="+schoolCode;
			$.ajax({
				url :url,
				async: false,
				data :{"schoolCode":schoolCode},
				success : function(data){
					if(data != null){
						if(data.schType == 1){
							if(stuGrade == 0){
								str = "一年级";
							}else if(stuGrade == 1){
								str = "二年级";
							}else if(stuGrade == 2){
								str = "三年级";
							}else if(stuGrade == 3){
								str = "四年级";
							}else if(stuGrade == 4){
								str = "五年级";
							}else if(stuGrade == 5){
								str = "六年级";
							}else{
								str = "六年级";
							}
						}else if(data.schType == 2){
							if(stuGrade == 0){
								str = "七年级";
							}else if(stuGrade == 1){
								str = "八年级";
							}else if(stuGrade == 2){
								str = "九年级";
							}else{
								str = "九年级";
							}
						}else if(data.schType == 3){
							if(stuGrade == 0){
								str = "大一";
							}else if(stuGrade == 1){
								str = "大二";
							}else if(stuGrade == 2){
								str = "大三";
							}else if(stuGrade == 3){
								str = "大四";
							}else{
								str = "大四";
							}
						}
					}else{
					   $("#stuGrade").val("");
				    }
				}
			});
			$("#stuGrade").val(str);
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/student/student/">学生列表</a></li>
		<li class="active"><a href="${ctx}/student/student/form?id=${student.id}">学生<shiro:hasPermission name="student:student:edit">${not empty student.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="student:student:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="student" action="${ctx}/student/student/save" method="post" class="form-horizontal" autocomplete="off">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">姓名：</label>
			<div class="controls">
				<form:input path="stuName" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">学号：</label>
			<div class="controls">
				<form:input path="stuCode" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">性别：</label>
			<div class="controls">
				<form:select path="gender" class="span2 minWidth">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('sex')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">民族：</label>
			<div class="controls">
				<form:select path="nation" class="span2 minWidth">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('nation')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出生日期：</label>
			<div class="controls">
				<input name="birthday" type="text" maxlength="20" class="input-medium Wdate "
					value="<fmt:formatDate value="${student.birthday}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:true});"/>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label"><font color="red">*</font>所属学校：</label>
			<div class="controls">
			   <sys:treeselect3 id="schoolCode" name="schoolCode" value="${student.schoolCode}" labelName="schoolName" labelValue="${student.schoolName}"
			    title="学校" url="/sysschool/sysSchool/schTreeData" cssClass="input-medium" layer = "true" notAllowSelectParent="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">入学年份：</label>
			<div class="controls">
				<form:input path="enrtYear" htmlEscape="false" maxlength="255" class="input-xlarge digits"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">年级：</label>
			<div class="controls">
				<form:input path="stuGrade" htmlEscape="false" maxlength="64" class="input-xlarg" disabled="true" value="${fns:getDictLabel(student.stuGrade,'stu_grade','')}"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><font color="red">*</font>所属班级：</label>
			<div class="controls">
			   <sys:treeselect2 id="classCode" name="classCode" value="${student.classCode}" labelName="className" labelValue="${student.className}"
			    title="班级" url="/classinfo/classInfo/classTreeData" cssClass="input-medium" layer = "true" notAllowSelectParent="true" notAllowSelectRoot="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:input path="remakes" htmlEscape="false" maxlength="255" class="input-xlarge"/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="student:student:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>